-
Notifications
You must be signed in to change notification settings - Fork 8k
ext/random: Various minor refactorings #18435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
2bf000c to
905e881
Compare
ext/random/random.c
Outdated
| size_t len = hexstr->len >> 1; | ||
| unsigned char *str = (unsigned char *) hexstr->val, c, l, d; | ||
| const unsigned char *str = (unsigned char *) hexstr->val; | ||
| unsigned char c, l, d; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could also be pulled into the for(). In fact php_hex2bin (which is referenced in the comment above this function) already does. It makes sense to keep the two functions aligned.
ext/random/randomizer.c
Outdated
| } | ||
|
|
||
| non_64: | ||
| non_64: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please drop this one, it's intentional.
905e881 to
038886a
Compare
TimWolla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except the hex2bin changes. Perhaps they should be done in a separate PR, since they are fixing an actual bug?
| const unsigned char *str = (unsigned char *) ZSTR_VAL(hexstr); | ||
| unsigned char *ptr = (unsigned char *) dest; | ||
| int is_letter, i = 0; | ||
| uint32_t i = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is a uint32_t used as an offset. Please:
| uint32_t i = 0; | |
| size_t i = 0; |
Alternatively pointer arithmetic could be used on str.
| size_t len = hexstr->len >> 1; | ||
| unsigned char *str = (unsigned char *) hexstr->val, c, l, d; | ||
| const unsigned char *str = (unsigned char *) ZSTR_VAL(hexstr); | ||
| unsigned char *ptr = (unsigned char *) dest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| unsigned char *ptr = (unsigned char *) dest; | |
| unsigned char *ptr = dest; |
Unnecessary cast from void*.
| size_t target_length = oldlen >> 1; | ||
| zend_string *str = zend_string_alloc(target_length, 0); | ||
| unsigned char *ret = (unsigned char *)ZSTR_VAL(str); | ||
| size_t i, j; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact here it was correct 😒
Commits should be reviewed in order.